package pl.edu.agh.agents.gui.actions;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;

import pl.edu.agh.agents.agent.SystemManager;
import pl.edu.agh.agents.gui.GUI;
import pl.edu.agh.agents.gui.GraphUtils;

public class IterationAction extends AbstractAction {
	private static final long serialVersionUID = -1940878883959876753L;
	private SystemManager systemManager = SystemManager.getInstance();
	private GraphUtils graphUtils = GraphUtils.getInstance();
	public static final int FOR_ONE = 0;
	public static final int FOR_ALL = 1;
	private int mode;
	private GUI gui;

	public IterationAction(String name, int mode, GUI gui) {
		super(name);

		this.mode = mode;
		this.gui = gui;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		switch (mode) {
		case FOR_ONE: systemManager.makeIterationForOne();
			break;
		case FOR_ALL: systemManager.makeIterationForAll();
			break;
		}

		// update colors of states
		graphUtils.colorStates(gui);

		// set every edge opacity to 100
		graphUtils.highlightAll(gui);
	}
}